package com.dtda.edu.miaosha.service.impl;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dtda.edu.miaosha.bo.MarketBo;
import com.dtda.edu.miaosha.dao.MarketPoMapper;
import com.dtda.edu.miaosha.po.MarketPo;
import com.dtda.edu.miaosha.service.MarketService;

/**
 * @author 袁强
 * @version 2019年3月1日 下午2:30:40
 * 类说明  
 */
@Service("marketService")
public class MarketServiceImpl implements MarketService {

	@Autowired
	private MarketPoMapper marketPoMapper;
	@Override
	public MarketBo selMarketByItemId(Integer itemId) {
		// TODO Auto-generated method stub
		MarketPo marketPo = marketPoMapper.selectByItemId(itemId);
		if(marketPo == null) {
			return null;     //未查询到该商品有秒杀活动
		}
		MarketBo marketBo = new MarketBo();
		BeanUtils.copyProperties(marketPo, marketBo);
		marketBo.setMarketItemPrice(BigDecimal.valueOf(marketPo.getMarketItemPrice()));
		//判断该商品活动状态
		Date now = new Date();
		if(marketBo.getStartDate().after(now)) {
			//活动未开始
			marketBo.setMarketStatus(0);
		}else if(marketBo.getEndDate().before(now)) {
			//活动已结束
			marketBo.setMarketStatus(2);
		}else {
			//活动正在进行中
			marketBo.setMarketStatus(1);
		}
		return marketBo;
	}
	@Override
	public void deleteByTitleId(Integer ItemId) {
		// TODO Auto-generated method stub
		 marketPoMapper.deleteByTitleId(ItemId);
	}  

}
